package com.zb.testview;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.widget.RelativeLayout;

/**
 * Created by ZhuBo on 2015/11/6.
 */
public class MyGroupView extends RelativeLayout {


    public MyGroupView(Context context) {
        super(context);
        Log.v("0504", "   +++super(context)+++  ");
        init();
    }

    public MyGroupView(Context context, AttributeSet attrs) {
        super(context, attrs);
        Log.v("0504", "   +++super(context, attrs)+++  ");
        init();
    }

    public MyGroupView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        Log.v("0504", "   +++super(context, attrs, defStyleAttr)+++  ");
        init();
    }

    public void init(){
//        TextView tv = (TextView) findViewById(R.id.tv);
//        tv.setText("哈哈哈哈哈哈");
    }

    @Override
    protected void onFinishInflate() {
        Log.v("0504", "   +++onFinishInflate+++  ");
        super.onFinishInflate();
    }

    @Override
    protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
        Log.v("0504", "   +++onFocusChanged+++    gainFocus = " + gainFocus);
        super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
    }

    @Override
    public void onWindowFocusChanged(boolean hasWindowFocus) {
        Log.v("0504", "   +++onWindowFocusChanged+++    hasWindowFocus = " + hasWindowFocus);
        super.onWindowFocusChanged(hasWindowFocus);
    }

    @Override
    protected void onAttachedToWindow() {
        Log.v("0504", "   +++onAttachedToWindow+++  ");
        super.onAttachedToWindow();
    }

    @Override
    protected void onVisibilityChanged(View changedView, int visibility) {
        Log.v("0504", "   +++onVisibilityChanged+++  visibility =" + visibility
                + "  ,是否是自己 = " + (changedView == this));
        super.onVisibilityChanged(changedView, visibility);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        Log.v("0504", "   +++onSizeChanged+++  w = " + w);
        super.onSizeChanged(w, h, oldw, oldh);
    }

    @Override
    protected void onWindowVisibilityChanged(int visibility) {
        Log.v("0504", "   +++onWindowVisibilityChanged+++  visibility =" + visibility);
        super.onWindowVisibilityChanged(visibility);
    }

    @Override
    protected void onDetachedFromWindow() {
        Log.v("0504", "   +++onDetachedFromWindow+++  ");
        super.onDetachedFromWindow();
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        Log.v("0504", "   +++onMeasure+++  ");
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        Log.v("0504", "   +++onLayout+++  ");
        super.onLayout(changed, left, top, right, bottom);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        Log.v("0504", "   +++onDraw+++  ");
        super.onDraw(canvas);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        Log.v("0504", "   +++dispatchTouchEvent+++  ");
        return super.dispatchTouchEvent(ev);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        Log.v("0504", "   +++onTouchEvent+++  ");
        return super.onTouchEvent(event);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        //拦截 相对于自己的子类
        //因此只有ViewGroup有
        Log.v("0504", "   +++onInterceptTouchEvent+++  ");
        return super.onInterceptTouchEvent(ev);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        Log.v("0504", "   +++onKeyDown+++  ");
        return super.onKeyDown(keyCode, event);
    }
}
